/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MantenimentFrame.java
 *
 * Created on 29-nov-2011, 6:23:09
 */
package edu.uoc.tdp.pac4.only5.gui.client;

import edu.uoc.tdp.pac4.only5.gui.client.panels.manteniment.UsuariPanel;
import edu.uoc.tdp.pac4.only5.gui.client.panels.manteniment.AulaPanel;
import edu.uoc.tdp.pac4.only5.manager.UserManager;
import edu.uoc.tdp.pac4.only5.manager.SpaceManager;
import edu.uoc.tdp.pac4.only5.manager.impl.DataBaseConnectionManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.UserManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.SpaceManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.ResourceManagerImpl;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alex
 */
public class MantenimentFrame extends javax.swing.JFrame {

    private UserManager userManager;
    private UsuariPanel usuariPanel;
    private SpaceManager spaceManager;
    private AulaPanel aulaPanel;

    /** Creates new form MantenimentFrame */
    public MantenimentFrame() {
        initComponents();
        this.setLayout(new FlowLayout());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu4 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        jMenu4.setText("File");
        jMenuBar2.add(jMenu4);

        jMenu5.setText("Edit");
        jMenuBar2.add(jMenu5);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jMenu1.setText("Manteniment");
        jMenu1.setToolTipText("");
        jMenu1.setActionCommand("Usuaris");

        jMenuItem1.setText("Usuaris");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnu_Usuari_ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Aules");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnu_Aula_ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Recursos");
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void mnu_Usuari_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnu_Usuari_ActionPerformed
// TODO add your handling code here:
        DesactivarPanels();
        try {
            userManager = new UserManagerImpl(DataBaseConnectionManagerImpl.getInstance());
            //userManager = (UserManager) Naming.lookup("rmi://localhost/UserManager");
        } catch (RemoteException ex) {
            Logger.getLogger(MantenimentFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        usuariPanel = new UsuariPanel(userManager);
        this.add(usuariPanel, BorderLayout.CENTER);
        this.pack();
}//GEN-LAST:event_mnu_Usuari_ActionPerformed

private void mnu_Aula_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnu_Aula_ActionPerformed
// TODO add your handling code here:
        DesactivarPanels();
        try {
            spaceManager = new SpaceManagerImpl(DataBaseConnectionManagerImpl.getInstance());
            //userManager = (UserManager) Naming.lookup("rmi://localhost/UserManager");
        } catch (RemoteException ex) {
            Logger.getLogger(MantenimentFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        aulaPanel = new AulaPanel(spaceManager);
        this.add(aulaPanel, BorderLayout.CENTER);
        this.pack();
}//GEN-LAST:event_mnu_Aula_ActionPerformed
    private void DesactivarPanels() {
// Aquest codi ve de AulesFrame.java !!!        
//        if(ClientSession.getInstance().getRole() != null){
//            if(ClientSession.getInstance().getRole().equals(EnumRole.TECNIC))
//                mnu_ConsultaAules.setEnabled(true);
//        }
//        try {
//            this.remove(consultaAulesPanel);
//        } catch (Exception e) {
//        }
    try{
        this.remove(usuariPanel);
        }
        catch(Exception e){
        }
    try{
        this.remove(aulaPanel);
        }
        catch(Exception e){
        }

        
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MantenimentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MantenimentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MantenimentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MantenimentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MantenimentFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    // End of variables declaration//GEN-END:variables
}
